package com.yoyo.schedule.task_manager;


import com.yoyo.schedule.TaskItemAndParameter;
import org.apache.zookeeper.data.Stat;

import java.util.List;
import java.util.Map;


public interface IDataManager {
    long zooKeeperCurrentTimeMillis();


    List<TaskItemAndParameter> getTaskItemAndParameterList(String taskType, String uuid) throws Exception;


    List<TaskItem> loadTaskItemList(String taskType) throws Exception;


    void releaseDealTaskItem(String taskType, String uuid) throws Exception;

    int getTaskItemCount(String taskType) throws Exception;


    TaskType loadBaseTaskType(String taskType) throws Exception;


    int clearExpireServers(String taskType, long expireTime) throws Exception;

    /**
     * @param serverIdList 可分配的
     */
    int createTaskItemIfNotFind(String taskType, List<String> serverIdList) throws Exception;

    List<TaskHandler> getTaskHandlerList(String taskType) throws Exception;

    List<String> loadServerIdList(String taskType) throws Exception;


    void assignTaskItem(String taskType, String currentUuid, int maxTaskItemsOfOneThreadGroup, List<String> serverIdList) throws Exception;


    boolean refreshHeartBeatTimeAndVersion(TaskHandler taskHandler) throws Exception;

    void registerTaskHandler(TaskHandler taskHandler) throws Exception;

    void unRegisterTaskHandler(String taskType, String uuid) throws Exception;

    void clearExpireTaskTypeRunningInfo(String baseTaskType, String serverUUID, double expireDateInternal) throws Exception;

    boolean isLeaderServerId(String uuid, List<String> serverList);

    //
    void pauseTaskType(String baseTaskType) throws Exception;

    void resumeTaskType(String baseTaskType) throws Exception;

    //
    List<TaskType> getBaseTaskTypeList() throws Exception;


    void clearTaskType(String baseTaskType) throws Exception;


    void createBaseTaskType(TaskType baseTaskType) throws Exception;

    void updateBaseTaskType(TaskType baseTaskType) throws Exception;

    List<TaskTypeRuntimeInfo> getTaskTypeRunInfoList(String baseTaskType) throws Exception;


    void deleteTaskType(String baseTaskType) throws Exception;


    List<TaskHandler> getTaskHandlerList(String baseTaskType, String ownSign, String ip, String orderStr)
            throws Exception;


    List<TaskHandler> getTaskHandlerListByMachineId(String managerFactoryUuid) throws Exception;


    void createTaskItemIfNotFind(TaskItem[] taskItems) throws Exception;


    void updateTaskItemStatus(String taskType, String taskItem, Status status, String message) throws Exception;


    void deleteTaskItem(String taskType, String taskItem) throws Exception;


    void createTaskItems(String baseTaskType, String ownSign, String uuid) throws Exception;

    void createTaskType(String baseTaskType, String ownSign) throws Exception;


    boolean isLeaderServer(String baseTaskType, String ownSign) throws Exception;

    void setTaskItemsWithServerId(String baseTaskType, String taskType, String uuid) throws Exception;

    String getLeaderServerId(List<String> serverNameList);

    long updateTaskItemFlag(String taskType) throws Exception;

    long getTaskItemStatVersion(String taskType) throws Exception;

    Map<String, Stat> getServerIdToStatMap(String taskType) throws Exception;

}
